<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>FNILocale test</title>
    <script type="text/javascript" src="../depencies/prototype/prototype.js"> </script>
    <script type="text/javascript" src="../depencies/fnievents/fnievents.js"> </script>
    <script type="text/javascript" src="../../../dist/fnilocale.js"> </script>
    <script type="text/javascript">
      var LOCALES = ['en_US', 'fi_FI']; 
      var _LOCALE;
    
      function getLocaleObject() {
        if (!_LOCALE) {
          _LOCALE = new fni.locale.FNILocale();
          for (var i = 0, l = LOCALES.length; i < l; i++) {
            _LOCALE.loadLocale(LOCALES[i], 'data/' + LOCALES[i] + '.json');            
          }
          _LOCALE.setLocale(LOCALES[0]);
        }

        return _LOCALE; 
      }

      function setLocale(locale) {
        window.location.href = '?locale=' + locale;
      }

      function addTitle(text) {
        addText('<b>' + text + '</b>');
      }

      function addText(text) {
        $('test').innerHTML += '<p>' + text + '</p>';
      }
    
      function init(event) {
        for (var i = 0, l = LOCALES.length; i < l; i++) {
          var localeLink = new Element('a', {href: 'javascript:setLocale("' + LOCALES[i] + '")'}).update(LOCALES[i]);
          var listItem = new Element('li').update(localeLink);  
          
          $('localeList').appendChild(listItem); 
        }

        if (window.location.search.length > 1) {
          var params = window.location.search.substring(1).split('&');
          for (var i = 0, l = params.length; i < l; i++) {
            var param = params[i].split('=');
            if (param[0] == 'locale') {
              getLocaleObject().setLocale(param[1]);
            }
          }
        }
        
        var now = new Date();

        addTitle('Localized text');
        addText(getLocaleObject().getText('test.helloworld'));
        
        addTitle('Localized text with parameters');
        addText(getLocaleObject().getText('test.webbrowser', navigator.userAgent));

        addTitle('Localized date (short version)');
        addText(getLocaleObject().getDate(now.getTime(), false));

        addTitle('Localized date (long version)');
        addText(getLocaleObject().getDate(now.getTime(), true));

        addTitle('Localized time');
        addText(getLocaleObject().getTime(now.getTime()));

        addTitle('Localized date time (short version)');
        addText(getLocaleObject().getDateTime(now.getTime(), false));

        addTitle('Localized date time (long version)');
        addText(getLocaleObject().getDateTime(now.getTime(), true));

        getLocaleObject().getDateTime(now.getTime(), true)
        
        addTitle('Date inside localized text');
        addText(getLocaleObject().getText('test.dateparam', getLocaleObject().getDate(now.getTime(), true), getLocaleObject().getTime(now.getTime())));
      }
    </script>
  </head>
  <body onload="init();">
    <p> <b> Change locale: </b> </p>
    
    <ul id="localeList">
      
    </ul>
  
    <p> <b> Samples: </b> </p>
  
    <div id="test">
      
    </div>
  </body>
</html>